// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { gif } from "../../TS/BASE/spineANDgif/gif";
import DES from "../../TS/Ditu/des/DES";
import GeZiManager from "../../TS/Manager/GeZiManager";
import MessageCenter from "../../TS/Message/MessageCenter";
import { FDUI } from "../../TS/UIS/else/FDUI";
import turn from "../../TS/game/time/turn";

const {ccclass, property} = cc._decorator;

@ccclass
export default class banana extends DES {
    ZB:number//坐标
    ObstaclesName:string//障碍物名
  FW:number[]=[]//作用范围
  gif:gif=null
  timeArray: number[]=[40,40,40,40,40,40,100,100,100,100,40,40,40,40,40,40,40,40,40,40,40,40,60,60,60,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40];
  
  onLoad(): void {
    this.gif=this.node.getComponent(gif)
  if(this.gif!=null){this.gif.timeArray=this.timeArray}
 
  }
  
  
  
  
  
  
  
  
  
  
  ObstacleClear()//清除当前坐标障碍物
  {
    for (let i = GeZiManager.AllObstacles.length - 1; i >= 0; i--) {
      if (GeZiManager.AllObstacles[i].ZB === this.ZB) {
          GeZiManager.AllObstacles.splice(i, 1);
      }
  }
  }
  BZ(preZB:number)
  {
     MessageCenter.MakeSHMessage("AM",[this.ZB],1,0,"getOne")


     console.log(GeZiManager.Tcharacter.turn8([GeZiManager.Tcharacter.faceIs(preZB)])[0])
     console.log(preZB)
     console.log(this.ZB)
if (preZB!=this.ZB) {
  MessageCenter.MakeSHMessage("AM",[this.ZB],[this.DfaceIs(preZB,this.ZB),0.4],turn.turn,"move")
}
  this.playFrameAnimation1("BZ",0,GeZiManager.Tcharacter.turn8([GeZiManager.Tcharacter.faceIs(preZB)])[0])
   
    this.ObstacleClear()
    this.node.removeComponent(FDUI)

  }
  
  
  
  
  playFrameAnimation1(n: string, loop: number, p: number): void {
      switch (n) {
        case "BZ"://this.moveto(0.8,this.findGe(p,1));  
        this.fadeOutAndDisappear(this.node,1000);
            break;
   
        default:
            break;
      }
  }
  
  LK(){}
  
  JR(){}



  DfaceIs(ZB: number,preZB:number) {

    let y;
    let x;

    if (ZB % 8 == 0) { x = 8 } else { x = ZB % 8; }
    y = Math.ceil(ZB / 8);

    let y2;
    let x2;

    if (preZB % 8 == 0) { x2 = 8 } else { x2 = preZB % 8; }
    y2 = Math.ceil(preZB / 8);






    if (preZB==ZB) {
      return 5; // 表示位置在原点
    } else if (x2 == x) {
      return y2 > y ? 8 : 2; // 表示位置在Y轴上
    } else if (y2 == y) {
      return x2 > x ? 6 : 4; // 表示位置在X轴上
    } else {
      if (x2 > x) {
        return y2 > y ? 9 : 3; // 表示位置在第一或第四象限
      } else {
        return y2 > y ? 7 : 1; // 表示位置在第二或第三象限
      }
    }
  }
}
